package com.celesea.auth.user.v1.controller;

import com.celesea.auth.user.entity.User;
import com.celesea.auth.user.service.UserService;
import com.celesea.framework.util.EnvUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author JackYuan
 * @create 2017-10-30 23:01
 */
@RestController
@RequestMapping("v1/api/users")
@Api(tags = "用户API接口")
public class UserApiController {
    @Autowired
    private UserService userService;

    @GetMapping("dept/{deptId}/positions/{positionCode}")
    @ApiOperation(value = "获取部门领导")
    public List<User> byDeptPosition(@PathVariable String deptId, @PathVariable String positionCode) {
        List<User> users = userService.selectByDeptPosition(EnvUtil.getTenantId(), deptId, positionCode);
        return users;
    }

    @GetMapping
    @ApiOperation(value = "根据ids查询用户")
    public List<User> get(List<String> ids) {
        return userService.findByIds(EnvUtil.getTenantId(), ids);
    }


    @GetMapping(value = "/{id}")
    @ApiOperation(value = "根据id查询用户")
    public User get(@PathVariable String id) {
        return userService.selectByPk(EnvUtil.getTenantId(), id);
    }

    @GetMapping(value = "/account/{account}")
    @ApiOperation(value = "根据account查询用户")
    public User getByAccount(@PathVariable String account) {
        return userService.selectByAccount(EnvUtil.getTenantId(), account);
    }

    @GetMapping(value = "/role/{roleId}")
    @ApiOperation(value = "根据roleId查询用户")
    public List<User> getByRole(@PathVariable String roleId) {
        return userService.selectByRole(EnvUtil.getTenantId(), roleId);
    }

    @GetMapping(value = "/group/{groupId}")
    @ApiOperation(value = "根据groupId查询用户")
    public List<User> getByGroup(@PathVariable String groupId) {
        return userService.selectByGroup(EnvUtil.getTenantId(), groupId);
    }

}
